#include "stdafx.h"

#include "FileItem.h"

FileItem::FileItem(const CString& fileName, const CString& pathName):
	isGetData(false),strFileName(fileName),strPathName(pathName),
	iconIndex(-1),isDataVaild(false)
{

}

void FileItem::CopyItem(const FileItem& rhs)
{
	isGetData = rhs.isGetData;
	strFileName = rhs.strFileName;
	strPathName = rhs.strPathName;
	if(isGetData)
	{
		fileSize = rhs.fileSize;
		lastWriteTime = rhs.lastWriteTime;
		iconIndex = rhs.iconIndex;
	}
}

FileItem::FileItem(const FileItem& rhs)
{
	CopyItem(rhs);
}

FileItem& FileItem::operator=(const FileItem& rhs)
{
	CopyItem(rhs);
	return *this;
}

bool FileItem::GetData()
{
	isGetData = true;
	CFileFind finder;
	if(finder.FindFile(strPathName))
	{
		finder.FindNextFile();
		fileSize = finder.GetLength();
		finder.GetLastWriteTime(lastWriteTime);
		finder.Close();
		isDataVaild = true;
	}
	else return false;

	SHFILEINFO shFinfo;
	SHGetFileInfo(strPathName, 0, &shFinfo, sizeof(shFinfo), SHGFI_ICON|SHGFI_LARGEICON);
	iconIndex = shFinfo.iIcon;

	return true;
}